package com.fs.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.fs.pojo.*;
import com.fs.service.OutstoService;
import com.fs.service.UserService;
import com.fs.service.WareHouseService;
import com.fs.util.ResponseDataUtil;
import com.fs.vo.Condition;
import com.fs.vo.ResponseData;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;

/**
 * @author hyy
 * @version 1.0
 * @description: 出库审批表控制层
 * @date 2024/10/18 19:21
 */
@RestController
@RequestMapping("/reverse/outsto")
public class OutstoController {

    @Autowired
    private OutstoService outstoService;

    @Autowired
    private UserService userService;

    @Autowired
    private WareHouseService wareHouseService;

    /**
     * 获取仓库，用户信息
     * @return
     */
    @GetMapping("/data")
    public ResponseData<HashMap> getData(Integer id){
        List<Wh_inventory> whWarehouses = wareHouseService.queryByProductId(id);
        List<User> users = userService.queryUsers(null);
        HashMap<Object, Object> map = new HashMap<>();
        map.put("warehouse",whWarehouses);
        map.put("users",users);
        return !map.isEmpty()? ResponseDataUtil.buildOk(map):ResponseDataUtil.buildFail(null);
    }

    /**
     * 更新出库审批信息
     * @param outsto
     * @return
     */
    @PostMapping("/update")
    public ResponseData updateOutsto(@RequestBody Outsto outsto){
        return outstoService.updateState(outsto)? ResponseDataUtil.buildOk("修改成功"):ResponseDataUtil.buildFail(null);
    }

    /**
     * 查询所有
     * @param condition
     * @return
     */
    @PostMapping("/query")
    public ResponseData<Page<Outsto>> queryAll(@RequestBody Condition<Outsto> condition){
        //审批表分页查询
        Page<Outsto> page = outstoService.queryAll(condition);
        return page!=null? ResponseDataUtil.buildOk(page):ResponseDataUtil.buildFail(null);
    }

    /**
     * 获取详情
     * @param id
     * @return
     */
    @GetMapping("/{id}")
    public ResponseData<Outsto> queryById(@PathVariable Integer id){
        //审批信息详情
        Outsto outsto = outstoService.queryById(id);
        return outsto!=null? ResponseDataUtil.buildOk(outsto):ResponseDataUtil.buildFail(null);
    }

    /**
     * 删除出库申请
     * @param id
     * @return
     */
    @DeleteMapping("/{id}")
    public ResponseData<Outsto> delOutsto(@PathVariable Integer id){
        //删除出库审批
        Integer outsto = outstoService.delOutsto(id);
        return outsto!=0? ResponseDataUtil.buildOk(outsto):ResponseDataUtil.buildFail(null);
    }
}
